package com.fenghuajueli.module_find_the_difference.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.widget.TextView;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.fenghuajueli.libbasecoreui.widget.RoundImageView;
import com.fenghuajueli.module_find_the_difference.R;
import com.fenghuajueli.module_find_the_difference.entity.Guanka;
import com.fenghuajueli.module_find_the_difference.zhao.ZhaoActivity;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.List;

public class GuankaAdapter extends BaseQuickAdapter<Guanka, BaseViewHolder> {
    private Context context;
    private HashMap<Integer, Integer> guankaMaps = new HashMap<>();
    public GuankaAdapter(Context context,int layoutResId, @Nullable List<Guanka> data) {
        super(layoutResId, data);
        this.context = context;
        initGuankaMaps();
    }


    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, Guanka guanka) {
        Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/baotuxiaobaiti.ttf");
        baseViewHolder.setText(R.id.tv_title, guanka.getTitle());
        ((TextView)baseViewHolder.getView(R.id.tv_title)).setTypeface(tf);
        ((TextView)baseViewHolder.getView(R.id.tv_unlock)).setTypeface(tf);
        Glide.with(context).load(guankaMaps.get(guanka.getGuankaId())).into((RoundImageView) baseViewHolder.getView(R.id.iv_guanka));

        if (guanka.isUnLocked()) {
            baseViewHolder.getView(R.id.cl_unlock).setVisibility(View.VISIBLE);
            baseViewHolder.getView(R.id.cl_lock).setVisibility(View.GONE);
        }else{
            baseViewHolder.getView(R.id.cl_lock).setVisibility(View.VISIBLE);
            baseViewHolder.getView(R.id.cl_unlock).setVisibility(View.GONE);
        }
        baseViewHolder.getView(R.id.cl_guanka).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (guanka.isUnLocked()) {
                    ZhaoActivity.start(context, guanka.getGuankaId());
                }else{
                    ToastUtils.showShort("当前关卡还未解锁，请先完成前面关卡~");
                }
            }
        });
    }

    private void initGuankaMaps() {
        guankaMaps.clear();
        guankaMaps.put(1, R.mipmap.a_19);
        guankaMaps.put(2, R.mipmap.a_07);
        guankaMaps.put(3, R.mipmap.a_22);
        guankaMaps.put(4, R.mipmap.a_01);
        guankaMaps.put(5, R.mipmap.a_02);
        guankaMaps.put(6, R.mipmap.a_03);
        guankaMaps.put(7, R.mipmap.a_04);
        guankaMaps.put(8, R.mipmap.a_05);
        guankaMaps.put(9, R.mipmap.a_06);
        guankaMaps.put(10, R.mipmap.a_14);
        guankaMaps.put(11, R.mipmap.a_08);
        guankaMaps.put(12, R.mipmap.a_09);
        guankaMaps.put(13, R.mipmap.a_10);
        guankaMaps.put(14, R.mipmap.a_11);
        guankaMaps.put(15, R.mipmap.a_12);
        guankaMaps.put(16, R.mipmap.a_13);
        guankaMaps.put(17, R.mipmap.a_15);
        guankaMaps.put(18, R.mipmap.a_25);
        guankaMaps.put(19, R.mipmap.a_17);
        guankaMaps.put(20, R.mipmap.a_18);
        guankaMaps.put(21, R.mipmap.a_20);
        guankaMaps.put(22, R.mipmap.a_21);
        guankaMaps.put(23, R.mipmap.a_26);
        guankaMaps.put(24, R.mipmap.a_23);
        guankaMaps.put(25, R.mipmap.a_24);
        guankaMaps.put(26, R.mipmap.a_16);
    }
}
